<% content_for :page_title do %>
  <%= page_header_back_button spree.admin_admin_users_path, @admin_user %>
  <%= @admin_user.name %>
<% end %>

<%= content_for :title do %>
  <%= @admin_user.name %>
<% end %>

<div class="row">
  <div class="col-lg-8">
    <div class="card mb-4">
      <div class="card-header">
        <h5 class="card-title">
          <%= icon 'history', class: 'mr-1' %>
          <%= Spree.t('admin.audit_log') %>
        </h5>
      </div>
      <div class="card-body">
        <%= render 'audit_log' %>
      </div>
    </div>
  </div>

  <div class="col-lg-4">
    <div class="card mb-4" id="user-details">
      <%= turbo_frame_tag :edit_user do %>
        <div class="card-header d-flex align-items-center justify-content-between">
          <h5 class="card-title">
            <%= Spree.t(:details) %>
          </h5>
          <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_admin_user_path(@admin_user), class: 'btn btn-light btn-sm', data: { turbo_frame: :edit_user } %>
        </div>
        <div class="card-body p-0">    
          <ul class="list-group list-group-flush">
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <%= Spree.t(:email) %>
              <span>
                <%= @admin_user.email %>
                <%= clipboard_component(@admin_user.email) %>
              </span>
            </li>
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <%= Spree.t(:name) %>
              <span>
                <%= @admin_user.name %>
              </span>
            </li>
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <%= Spree.t(:roles) %>
              <span>
                <% @role_users.each do |role_user| %>
                  <span class="badge badge-light"><%= role_user.role.name %></span>
                <% end %>
              </span>
            </li>
            <% if @admin_user.respond_to?(:sign_in_count) %>
              <li class="list-group-item d-flex justify-content-between align-items-center">
                <%= I18n.t('activerecord.attributes.user.sign_in_count') %>
                <span>
                  <%= @admin_user.sign_in_count %>
                </span>
              </li>
            <% end %>
            <% if @admin_user.respond_to?(:last_sign_in_at) %>
              <li class="list-group-item d-flex justify-content-between align-items-center">
                <%= I18n.t('activerecord.attributes.user.last_sign_in') %>
                <span>
                  <% if @admin_user.last_sign_in_at %>
                    <%= spree_time(@admin_user.last_sign_in_at) %>
                  <% else %>
                    <%= Spree.t(:not_available) %>
                  <% end %>
                </span>
              </li>
            <% end %>
            <% if @admin_user.respond_to?(:current_sign_in_at) %>
              <li class="list-group-item d-flex justify-content-between align-items-center">
                <%= I18n.t('activerecord.attributes.user.current_sign_in') %>
                <span>
                  <% if @admin_user.current_sign_in_at %>
                    <%= spree_time(@admin_user.current_sign_in_at) %>
                  <% else %>
                    <%= Spree.t(:not_available) %>
                  <% end %>
                </span>
              </li>
            <% end %>
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <%= Spree.t(:created_at) %>
              <span>
                <%= spree_time(@admin_user.created_at) %>
              </span>
            </li>
            <li class="list-group-item d-flex justify-content-between align-items-center">
              <%= Spree.t(:updated_at) %>
              <span>
                <%= spree_time(@admin_user.updated_at) %>
              </span>
            </li>
            <% if @admin_user.invited_by %>
              <li class="list-group-item d-flex justify-content-between align-items-center">
                <%= Spree.t(:invited_by) %>
                <span>
                  <%= link_to @admin_user.invited_by.email, spree.admin_admin_user_path(@admin_user.invited_by), class: 'text-decoration-none', data: { turbo_frame: '_top' } %>
                </span>
              </li>
            <% end %>
          </ul>
        </div>
      <% end %>
    </div>
  </div>
</div>